<template>
  <div class="personal">
    <div class="personal-title">个人账号管理</div>
    <dl class="user-account clear">
      <dt class="avatar">
        <img :src="userInfo.userHeadUrl" />

        <span class="modify-avatar" @click="modifyAvatar">修改头像</span>
      </dt>
      <dd class="account-info">
        <p class="user-name">
          <span class="name" v-if="flag">
            {{ input !== "" ? input : "请设置您的初始昵称" }}
            <i
              @click="setName"
              class="icon-size iconfont iconbianji cl-iconfont is-square"
            ></i>
          </span>
          <template v-else>
            <el-input
              maxlength="20"
              show-word-limit
              v-model="input"
              placeholder="请输入内容"
            ></el-input>
            <span @click="blur">保存</span>
            <span @click="cancelSetName">取消</span>
          </template>
        </p>
        <p class="create-time">
          创建时间:
          <i>{{ createTime }}</i>
        </p>
      </dd>
    </dl>
    <ul class="social-list">
      <li class="mobilePhone">
        <div class="left-wrap">
          <i class="iconfont iconshouji"></i>
          <span class="set-name">手机号码</span>
          <span class="social-desc"
            >手机号同时也是您的平台账号，可直接使用手机号登录管理平台，登录地址：login.mofuncloud.com</span
          >
        </div>
        <div class="right-wrap">
          <span class="user-value">{{ userInfo.phoneNumber }}</span>

          <span class="pd-left">
            <i class="iconfont iconxingzhuangjiehe isbind"></i>
            <div class="bind isbind">已绑定</div>
            |
            <button @click="modifiPhoneNum">修改</button>
          </span>
        </div>
      </li>
      <li class="password">
        <div class="left-wrap">
          <i class="iconfont iconmima"></i>
          <span class="set-name">登录密码</span>
          <span class="social-desc"
            >设置登录密码，可使用手机号+密码登录管理平台，为保证帐号更加安全，建议您定期修改密码</span
          >
        </div>
        <div class="right-wrap">
          <span class="user-value" v-if="pwdTitle != '0'">******</span>
          <span class="pd-left">
            <i class="iconfont iconxingzhuangjiehe isbind"></i>
            <div class="bind" :class="pwdTitle == '1' ? 'isbind' : 'isbind'">
              {{ pwdTitle == "0" ? "已设置" : "已设置" }}
            </div>
            |
            <button @click="modifiPwd">{{ pwdBtn }}</button>
          </span>
        </div>
      </li>
    </ul>
    <el-dialog
      width="0"
      :close-on-click-modal="false"
      :show-close="false"
      :append-to-body="false"
      :visible.sync="
        $store.state.isRightPanelShow || $store.state.isInvitationPanelShow
      "
    >
      <right-pannel :style="{ width: pannelWidth + 'px' }">
        <span slot="title-text">{{ titText }}</span>
        <component
          v-if="
            $store.state.isRightPanelShow || $store.state.isInvitationPanelShow
          "
          :is="curComponent"
          :sourcePhone="userInfo.phoneNumber"
          :provider="CurrentProvider"
          :imageUrl="userInfo.userHeadUrl"
          :defaultAvatarHeadUrl="defaultAvatarHeadUrl"
          :isSetPassWord="userInfo.isSetPassWord"
          @setPwdTitleAndBtn="_setPwdTitleAndBtn"
          @getUserProfileAsync="_getUserProfileAsync"
        ></component>
      </right-pannel>
    </el-dialog>
  </div>
</template>
<script>
import RightPannel from "_c/RightPannel";
import SetAvatar from "./SetAvatar";
import SetPhoneNumber from "./SetPhoneNumber";
import SetPwd from "./SetPwd";
import { mapMutations } from "vuex";
import { formatDateTime } from "@/api/index.js";
import { updateUserName } from "@/api/index.js";
//
import * as personlApi from "@/api/request/personlApi";
export default {
  data() {
    return {
      // defaultAvatar: require("../../assets/defualtAvatar.png"),
      input: "",
      flag: true,
      userInfo: { phoneNumber: "", userHeadUrl: "" },
      curComponent: "",
      titText: "修改手机号",
      ExternalUsers: null,
      WeChatUser: null,
      AlipayUser: null,
      DingDingUser: null,
      WeChatJsLoginParams: null,
      CurrentProvider: "",
      weixinHtml: "",
      createTime: "",
      defaultAvatarHeadUrl: false,
      // alipayBindTip: false,
      pwdTitle: "0",
      pwdBtn: "设置",
      timeAlipay: 1,
      binSuccess: false,
      messageShow: "支付宝绑定中",
      messageShowIf: false,
      iconShow: true,
    };
  },
  components: {
    RightPannel,
    SetPhoneNumber,
    SetPwd,
    SetAvatar,
  },
  created() {
    this._getUserProfileAsync();
  },
  /* 局部过滤器 */
  filters: {
    geTel(tel) {
      // var reg = /^(\d{3})\d{4}(\d{4})$/;
      // return tel.replace(reg, "$1****$2");
    },
  },
  methods: {
    ...mapMutations(["ISRIGHTPANNELSHOW"]),
    _setPwdTitleAndBtn() {
      this.pwdTitle = "1";
      this.pwdBtn = "修改";
      this.userInfo.isSetPassWord = true;
      this.is;
    },
    async _getUserProfileAsync() {
      let { data } = await personlApi.getUserProfile();
      this.userInfo = data;
      if (data.displayName) {
        this.input = data.displayName;
      } else {
        this.input = "请输入您的初始昵称";
      }

      this.oldUserName = data.displayName;
      this.createTime = formatDateTime(data.createTime, "yyyy-MM-dd hh:mm");
      if (this.userInfo.isSetPassWord) {
        this._setPwdTitleAndBtn();
      }
      if (!data.userHeadUrl) {
        this.defaultAvatarHeadUrl = true;
        this.userInfo.userHeadUrl = this.defaultAvatar;
      } else {
        this.defaultAvatarHeadUrl = false;
      }
    },
    modifyAvatar() {
      this.curComponent = SetAvatar;
      this.titText = "修改头像";
      this.ISRIGHTPANNELSHOW(true);
    },
    // 修改手机号
    modifiPhoneNum() {
      this.titText = "修改手机号";
      this.curComponent = SetPhoneNumber;
      let coDe = "FindPwd";
      sessionStorage.setItem("coDe", coDe);
      this.ISRIGHTPANNELSHOW(true);
    },
    //修改密码||设置密码
    modifiPwd() {
      this.curComponent = SetPwd;
      if (this.userInfo.isSetPassWord) {
        this.titText = "修改密码";
      } else {
        this.titText = "设置密码";
      }
      let coDe = "ChangePwd";
      sessionStorage.setItem("coDe", coDe);
      this.ISRIGHTPANNELSHOW(true);
    },
    setName() {
      this.flag = false;
    },
    // 修改名称
    async blur() {
      if (this.input) {
        if (this.input.split(" ").join("").length !== 0) {
          this.flag = true;

          let { status } = await personlApi.ChangeDisplayName(this.input);
          if (status === 200) {
            this.$notify({
              customClass: "notify-success",
              message: `设置成功!`,
              showClose: false,
              duration: 1500,
            });
            this.oldUserName = this.input;
            this.$store.dispatch("_getAppHeadInfo");
          } else {
            this.$notify({
              customClass: "notify-error",
              message: `设置失败!`,
              showClose: false,
              duration: 1500,
            });
          }
        } else {
          this.$message({
            showClose: true,
            message: "昵称不能为空",
            type: "warning",
          });
        }
      } else {
        this.$message({
          showClose: true,
          message: "昵称不能为空",
          type: "warning",
        });
      }
    },
    // 取消修改名称
    cancelSetName() {
      this.input = this.oldUserName;
      this.flag = true;
    },
    modifyAvatar() {
      this.curComponent = SetAvatar;
      this.titText = "修改头像";
      this.ISRIGHTPANNELSHOW(true);
    },
  },
  computed: {
    pannelWidth() {
      return this.$store.state.isRightPanelShow === true ? 470 : 0;
    },
  },
};
</script>

<style scoped>
.el-input /deep/ .el-input__inner {
  padding-right: 60px;
}
</style>

<style lang="scss" scoped>
.personal {
  padding: 24px 16px;
  .personal-title {
    border-left: 2px solid $--color-primary;
    padding-left: 8px;
    font-size: $--font-size-base;
    font-weight: 700;
  }
  .user-account {
    background: #fff;
    display: flex;
    align-items: center;
    padding: 32px;
    margin: 24px 0 16px;
    border: $--border-base;
    // background-image: url("~img/personal/background.png");
    background-repeat: no-repeat;
    background-position: right;
    background-size: 750px;
    .avatar {
      float: left;
      width: 100px;
      height: 100px;
      position: relative;
      overflow: hidden;
      border-radius: 50%;
      img {
        width: 100%;
        height: 100%;
      }
      .modify-avatar {
        cursor: pointer;
        display: none;
        position: absolute;
        left: 0;
        bottom: 0;
        background: #262626;
        opacity: 0.6;
        color: #fff;
        padding: 5px;
        width: 100%;
        text-align: center;
        box-sizing: border-box;
      }
      &:hover .modify-avatar {
        display: block;
      }
    }
    .account-info {
      float: left;
      padding-left: 40px;
      p {
        font-size: 14px;
        line-height: 22px;
      }
      .user-name {
        display: flex;
        align-items: center;
        .name {
          color: #262626;
          font-size: 14px;
          padding-left: 0;
        }
        > span {
          cursor: pointer;
          flex: none;
          color: $--color-primary;
          padding-left: 16px;
        }
      }
      .create-time {
        color: #8c8c8c;
        padding-top: 8px;
      }
      // p {
      //     height: 32px;
      //     line-height: 32px;
      // }
    }
  }
  .social-list {
    background: #fff;
    border: $--border-base;
    height: 460px;
    padding-top: 8px;
    li {
      padding: 0 32px;
      height: 50px;
      box-sizing: border-box;
      border-bottom: 1px solid #ebeced;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .left-wrap {
        display: flex;
        align-items: center;
        .iconfont {
          font-size: 20px;
        }
      }
      .right-wrap {
        display: flex;
        align-items: center;
        .user-value {
          color: #8c8c8c;
          display: flex;
          align-items: center;
          img {
            width: 20px;
            height: 20px;
            border-radius: 50%;
            vertical-align: top;
            margin-right: 8px;
          }
        }
      }
      .set-name {
        display: inline-block;
        width: 105px;
        font-size: $--font-size-small;
        color: $--color-text-primary;
        margin-left: 14px;
      }
    }

    .pd-left {
      padding-left: 40px;
      color: #eee;
      & :last-child {
        padding-left: 15px;
        color: #0895e6;
      }
      .bind {
        padding-right: 15px;
        padding-left: 10px;
        display: inline-block;
      }
      .notbind {
        color: $--color-danger;
      }
      .isbind {
        color: $--color-success;
      }
    }
    .social-desc {
      color: #8c8c8c;
    }
  }
}

//////////////
.assistantsTxt {
  font-size: 28px;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #ffffff;
  margin-top: 40px;
}

.assistantsMax {
  z-index: 200;
}

.assistants {
  cursor: pointer;
  outline: none;
  width: 620px;
  height: 620px;
  background: #000;
}
//手机预览样式
.message-view {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(38, 38, 38, 0.6);
  z-index: 2000;
  .phone {
    position: relative;
    width: 300px;
    margin: 15% auto 0;
    background: $--color-white;
    border-radius: 6px;
    .line {
      position: absolute;
      top: 22px;
      left: 134px;
      width: 32px;
      height: 2px;
      border-radius: 1px;
      background: rgba(229, 229, 229, 1);
      border-radius: 6px;
    }
    .iconguanbi {
      position: absolute;
      top: 0;
      right: -70px;
      padding: 8px;
      font-size: 18px;
      font-weight: 600;
      color: $--color-text-secondary;
      border-radius: $--border-radius-circle;
      &:hover {
        color: $--color-primary;
      }
    }
    div {
      p {
        position: relative;
        width: 240px;
        min-height: 70px;
        margin: 40px 0 0 20px;
        padding: 10px 6px;
        background: $--background-color-base;
        border-radius: 2px 2px 2px 0px;
        border-radius: $--border-radius-base;
        font-size: $--font-size-small;
        font-weight: 400;
        color: $--color-text-primary;
        line-height: 20px;
        .arrow {
          position: absolute;
          left: -12px;
          bottom: 0;
          width: 0;
          height: 0;
          border-bottom: 10px solid $--background-color-base;
          border-left: 12px solid transparent;
        }
      }
    }
    .formdata-message {
      padding: 32px;
    }
    .formdatatitie {
      color: rgba(38, 38, 38, 1);
      font-size: 16px;
      font-weight: bold;
      margin-bottom: 12px;
    }
    .formdatacontentTxt1 {
      color: rgba(38, 38, 38, 1);
      font-size: 16px;
      margin-bottom: 6px;
    }
    .formdatacontentTxt2 {
      color: rgba(100, 100, 100, 1);
      font-size: 14px;
      margin-bottom: 12px;
    }
  }
}

.c-iconShow {
  // display: none;
}
.mandle {
  position: fixed;
  top: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  width: 100vw;
  background: rgba(38, 38, 38, 0.6);
}
.el-message-box__status + .el-message-box__message {
  padding-left: 36px;
  padding-right: 12px;
}

.el-message-box__status {
  position: absolute;
  top: 50%;
  -webkit-transform: translateY(-50%);
  transform: translateY(-50%);
  font-size: 24px !important;
}

.icon-warning {
  width: 24px;
  height: 24px;
  background: url()
    no-repeat 50%;
  background-size: contain;
}
.icon-success {
  width: 24px;
  height: 24px;
  background: url()
    no-repeat 50%;
  background-size: contain;
}

.el-message-box__container {
  position: relative;
}

.el-message-box__content {
  padding: 40px 40px 70px 40px;
  color: #262626;
  font-size: 14px;
}

.el-message-box {
  padding: 34px 24px 29px;
  width: 520px;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  display: inline-block;
  width: 420px;
  padding-bottom: 10px;
  vertical-align: middle;
  background-color: #fff;
  border-radius: 4px;
  border: 1px solid #ebeef5;
  font-size: 18px;
  -webkit-box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  text-align: left;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}
.el-message-box__header {
  font-size: 16px;
}
</style>

